import React, { Component } from 'react';
import { connect } from 'react-redux';
import { loginAction } from '../actions/loginActions';
import '../busi/main.css';
import pageQuery from '../comm/fn';

class LinkPath extends Component {
    state = {
        loginInfo: {
            curPage: "",
            curName: "",
            subPage: [],
            prtPage: [],
            userName: "",
            userRole: "",
            loginID: "",
            errorInfo: "",
        }
    }
    componentDidMount() {
        this.setState({
            ...this.state,
            loginInfo: this.props.loginInfo,
        })
    }
    render(){
        let prtPages = this.state.loginInfo.prtPage;
        return undefined === prtPages || null === prtPages ? (
            <div></div>
        ) : (
            prtPages.map(prtpg => {
                return (
                    <span key={prtpg.page_path}>
                        <span onClick={() => pageQuery(prtpg.page_path)} className='alink'>{prtpg.page_name}</span>
                        <label> / </label>
                    </span>
                )
            })
        )
    }
}

const mapStateToProps = (state) => {
    return {
        loginInfo: state.loginInfo
    }
}

const mapDispatchToProps = (dispatch) => {
    return {
        loginAction: (loginInfo) => dispatch(loginAction(loginInfo))
    }
}

export default connect(mapStateToProps, mapDispatchToProps)(LinkPath);
